package com.hopes.bizz.basic.gis.controller;

import com.hopes.bizz.basic.hazard.source.entity.HazHazardSourceEntity;
import com.hopes.bizz.basic.hazard.source.service.HazHazardSourceService;
import com.hopes.bizz.basic.hazard.source.service.HazMonitorFactorService;
import com.hopes.boss.common.core.util.R;
import com.hopes.boss.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.stream.Collectors;

/**
 * @author yumr
 * @ProjectName bizz
 * @Description 重大危险源一张图
 * @time 2024/1/18 18:54
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/gis/hazard")
@Tag(description = "gis-hazard", name = "重大危险源一张图")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class HazardGisController {

    private final HazHazardSourceService hazHazardSourceService;

    private final HazMonitorFactorService hazMonitorFactorService;

    /**
     * 重大危险源分级统计
     *
     * @return R
     */
    @Operation(summary = "重大危险源分级统计", description = "重大危险源分级统计")
    @SysLog("重大危险源分级统计")
    @GetMapping("/level/count")
    public R hazardSourceLevelCount() {
        return R.ok(hazHazardSourceService.hazardSourceLevelCount());
    }

    /**
     * 传感器监测数量统计
     * @return R
     */
    @Operation(summary = "传感器监测数量统计", description = "传感器监测数量统计")
    @SysLog("传感器监测数量统计")
    @GetMapping("/sensor/count")
    public R hazardSensorClassifyCount() {
        return R.ok(hazHazardSourceService.hazardSensorClassifyCount());
    }

    /**
     * 视频监控数量统计
     * @return R
     */
    @Operation(summary = "视频监控数量统计", description = "视频监控数量统计")
    @SysLog("视频监控数量统计")
    @GetMapping("/video/count")
    public R hazardVideoNumberCount() {
        return R.ok(hazHazardSourceService.hazardVideoNumberCount());
    }

    /**
     * 实时监控
     *
     * @return R
     */
    @Operation(summary = "实时监控", description = "实时监控")
    @SysLog("实时监控")
    @GetMapping("om")
    public R om() {
        return R.ok(hazHazardSourceService.gisOm());
    }

    /**
     * 重大危险源 图层
     *
     * @return R
     */
    @Operation(summary = "重大危险源 图层", description = "重大危险源 图层")
    @SysLog("重大危险源 图层")
    @GetMapping("/layer/source")
    public R hazardSourceLayer() {
        return R.ok(hazHazardSourceService.list().stream().collect(Collectors.groupingBy(HazHazardSourceEntity::getHazardSourceLevel)));
    }

    /**
     * 监测参数 图层
     *
     * @return R
     */
    @Operation(summary = "监测参数 图层", description = "监测参数 图层")
    @SysLog("监测参数 图层")
    @GetMapping("/layer/monitorFactor")
    public R monitorFactorLayer() {
        return R.ok(hazMonitorFactorService.list());
    }
}
